<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>验收单据查询</title>
	<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
	<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link>
	<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script>
	<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

	<script type="text/javascript" src="/static/js/date.js"></script>
	<script src="/static/js/FileSaver.min.js"></script>
	<script src="/static/js/xlsx.full.min.js"></script>
	<script type="text/javascript">

        var url;
        // 屏蔽右键 变为菜单那
        $(function () {
            $(document).bind('contextmenu', function (e) {
                e.preventDefault();
                $('#tree-0').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            });
        });

        //项目列表选择
        function openProjListChoose(){
            $("#projList").dialog("open").dialog("setTitle","进入项目选择");
            $("#projTree").tree({
                url:'/admin/project/loadProjectTree',
                onLoadSuccess:function(node,data){
                    $("#tree").tree('expandAll');
                },
                //右键选择树形菜单操作
                onContextMenu: function (e, node) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    var rootNodes = $("#tree").tree('getRoots');
                    for (var i = 0; i < rootNodes.length; i++) {
                        var theNode = $("#tree").tree('find', rootNodes[i].id);
                        $("#tree").tree('uncheck', theNode.target);
                    }
                    $("#tree").tree('select', node.target);
                    if (node.attributes.state == 2) {
                        $("#tree-2").menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    } else if (node.attributes.state == 1) {
                        $("#tree-1").menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    } else {
                        $('#tree-0').menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    }

                },
                //单击某类别 展示不同详细和按钮选择
                onClick: function (node) {
                    if (node.attributes.state == 2) { // 假如是二级菜单,可以删除
                        $("#projNameList").datagrid('load', {
                            "w_id": node.id
                        });
                    } else if (node.attributes.state == 1) {
                        $("#projNameList").datagrid('load', {
                            "o_id": node.id
                        });
                    }
                }
            });
            loadDataGrid();
        }

        //加载项目数据表格
        function loadDataGrid() {
            $("#projNameList").datagrid({
                //双击事件
                onDblClickRow: function (index,row){
                    $("#projId").val(row.id);
                    $("#projName").val(row.xiangmumingcheng);
                    $("#projList").dialog("close");
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });
        }

        //仓库列表选择
        function openStoreListChoose(){
            $("#storeList").dialog("open").dialog("setTitle","进入仓库选择");
            $("#storeTree").tree({
                url:'/admin/kufang/loadKufangTree',
                onLoadSuccess:function(node,data){
                    $("#storeTree").tree('expandAll');
                },
                //右键选择树形菜单操作
                onContextMenu: function (e, node) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    var rootNodes = $("#tree").tree('getRoots');
                    for (var i = 0; i < rootNodes.length; i++) {
                        var theNode = $("#tree").tree('find', rootNodes[i].id);
                        $("#tree").tree('uncheck', theNode.target);
                    }
                    $("#tree").tree('select', node.target);
                    if (node.attributes.state == 2) {
                        $("#tree-2").menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    } else if (node.attributes.state == 1) {
                        $("#tree-1").menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    } else {
                        $('#tree-0').menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    }

                },
                //单击某类别 展示不同详细和按钮选择
                onClick: function (node) {
                    if (node.attributes.state == 2) { // 假如是二级菜单,可以删除
                        $("#storeNameList").datagrid('load', {
                            "w_id": node.id
                        });
                    } else if (node.attributes.state == 1) {
                        $("#storeNameList").datagrid('load', {
                            "o_id": node.id
                        });
                    }
                }
            });
            loadKufangDataGrid();
        }

        //加载项目数据表格
        function loadKufangDataGrid() {
            $("#storeNameList").datagrid({
                //双击事件
                onDblClickRow: function (index, row) {
                    $("#storeId").val(row.id);
                    $("#storeName").val(row.kufangmingcheng);
                    $("#storeList").dialog("close");
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });
        }

        //加载项目tree类别
        function openDeptListChoose() {
            $("#deptList").dialog("open").dialog("setTitle", "选择发料单位");
            $("#deptTree").tree({
                url: '/admin/bumen/loadBumenTree',
                onLoadSuccess: function (node, data) {
                    $("#deptTree").tree('expandAll');
                },
                onDblClick: function (node) {

                },
                //右键选择树形菜单操作
                onContextMenu: function (e, node) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                },
                //单击某类别 展示不同详细和按钮选择
                onClick: function (node) {
                    if (node.attributes.state == 2) { // 假如是二级菜单,可以删除
                        $("#deptNameList").datagrid('load', {
                            "w_id": node.id
                        });
                    } else if (node.attributes.state == 1) {
                        $("#deptNameList").datagrid('load', {
                            "o_id": node.id
                        });
                    }
                }
            });
            loadDeptDataGrid();
        }

        //加载部门数据表格
        function loadDeptDataGrid() {
            $("#deptNameList").datagrid({
                //双击事件
                onDblClickRow: function (index, row) {
                    $("#deptId").val(row.id);
                    $("#deptName").val(row.bumenmingcheng);
                    $("#deptList").dialog("close");
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                },
            });
        }

        // 查询项目
        function searchProj() {
            $("#projNameList").datagrid('load', {
                "codeOrProjName": $("#s_codeOrProjName").val()
            })
        }

        // 查询部门
        function searchDept() {
            $("#deptNameList").datagrid('load', {
                "codeOrDeptName": $("#s_codeOrDeptName").val()
            })
        }

        //查询库房
        function searchStore() {
            $("#storeNameList").datagrid('load', {
                "codeOrStoreName": $("#s_codeOrStoreName").val()
            })
        }

        //保存项目选择
        function saveProjChoose() {
            var node = $('#projTree').tree('getSelected'); // 获取选中节点
            $("#projId").val(node.id);
            $("#projName").val(node.text);
            $("#projList").dialog("close");
        }

        //保存部门选择 条目->文本
        function saveDeptChoose() {
            var node = $('#deptTree').tree('getSelected'); // 获取选中节点
            $("#deptId").val(node.id);
            $("#deptName").val(node.text);
            $("#deptList").dialog("close");
        }

        //保存库房选择
        function saveStoreChoose() {
            var node = $('#storeTree').tree('getSelected');
            $("#storeId").val(node.id);
            $("#storeName").val(node.text);
            $("#storeList").dialog("close");
        }


        $(document).ready(function(){
            $("#s_btime").datebox("setValue",genLastMonthDayStr()); // 设置上个月日期
            $("#s_etime").datebox("setValue",genTodayStr()); // 设置当前日期

            $('#dg').datagrid({
                onClickRow: function(index,row){
                    $("#dg2").datagrid({
                        url:'/admin/yanshoudan/listDetailsByZId',
                        queryParams:{
                            zongzhangid:row.id
                        },
                        onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                            e.preventDefault(); //阻止浏览器捕获右键事件
                            $(this).datagrid("clearSelections"); //取消所有选中项
                            $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                            $('#grid-data').menu('show', {
                                left: e.pageX,//在鼠标点击处显示菜单
                                top: e.pageY
                            });
                            e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                        },
                    });
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });

        });

        //搜索验收单
        function searchYanshoudan(){
            $('#dg2').datagrid('loadData', { total: 0, rows: [] });
            var projName = $("#projName").val();
            var xiangmumingcheng;
            if(projName.length==0){
                xiangmumingcheng = "";
            }else{
                xiangmumingcheng=projName;
            }

            var deptName = $("#deptName").val();
            var faliaodanwei;
            if(deptName.length==0){
                faliaodanwei = "";
            }else{
                faliaodanwei=deptName;
            }

            var storeName = $("#storeName").val();
            var rukukufang;
            if(storeName.length==0){
                rukukufang = "";
            }else{
                rukukufang=storeName;
            }

            $("#dg").datagrid({
                url:'/admin/yanshoudan/getSelective',
                queryParams:{
                    wuliaoyanshoudanhao:$("#s_danhao").val(),
                    xiangmumingcheng:xiangmumingcheng,
                    faliaodanwei:faliaodanwei,
                    rukukufang:rukukufang,
                    s_btime:$("#s_btime").datebox("getValue"),
                    s_etime:$("#s_etime").datebox("getValue")
                },
				onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });
        }
        //删除到货单
        function deleteYanshoudan(){
            var selectedRows=$("#dg").datagrid("getSelections");
            if(selectedRows.length==0){
                $.messager.alert("系统提示","请选择要删除的到货单！");
                return;
            }
            var ids = new Array();
            if(selectedRows.length>1){
                for(var i=0;i<selectedRows.length;i++){
                    ids.push(selectedRows[i].id);
                }
            }else if(selectedRows.length==1){
                var id = selectedRows[0].id;
                ids.push(id);
            }
            $.messager.confirm("系统提示","<font color=red>删除到货单后将无法恢复，是否删除？</font>",function(r){
                if(r){
                    $.post("/admin/yanshoudan/delete",{'ids':ids},function(result){
                        if(result.success){
                            $("#dg").datagrid("reload");
                            $("#dg2").datagrid("reload");
                        }else{
                            $.messager.alert("系统提示",result.errorInfo);
                        }
                    },"json");
                }
            });
        }

	</script>
</head>
<body class="easyui-layout" style="margin: 1px">
<div region="north" style="height: 350px;">
	<table id="dg" title="验收单据查询" class="easyui-datagrid" fit=true
		   fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
		   toolbar="#tb" >
		<thead>
		<tr>
			<!--展示验收单主表-->
			<!--<th field="ukyo" align="center" width="30" checkbox="true"></th>-->
			<th field="id" width="30" align="center" sortable="true" hidden="true">id</th>
			<th field="wuliaoyanshoudanhao" width="80" align="center" sortable="true">验收单单号</th>
			<th field="xiangmumingcheng" width="50" align="center" sortable="true">项目名称</th>
			<th field="faliaodanwei" width="50" align="center" sortable="true">发料单位</th>
			<th field="rukukufang" width="50" align="center" sortable="true">入库库房</th>
			<th field="daohuoshijian" width="50" align="center" sortable="true">到货时间</th>
			<th field="yanshouriqi" width="50" align="center" sortable="true">验收时间</th>
			<th field="chengyunchehao" width="50" align="center" sortable="true">承运车号</th>
			<th field="yundanhao" width="50" align="center" sortable="true">运单号</th>
			<th field="beizhu" width="50" align="center" sortable="true">备注</th>
			<th field="founder" width="50" align="center" sortable="true">创建人</th>
			<th field="createtime" width="70" align="center" sortable="true">创建时间</th>
		</tr>
		</thead>
	</table>

	<div id="tb">
		<div style="padding-bottom: 5px">
			<fieldset style="border-color: #E7F0FF">
				<legend>查询设置</legend>
				&nbsp;单据号：&nbsp;
				<input type="text" id="s_danhao" name="wuliaoyanshoudanhao" size="15" onkeydown="if(event.keyCode==13) searchYanshoudan()"/>
				&nbsp;&nbsp;&nbsp;&nbsp;项目选择：<input type="text" id="projName" name="xiangmumingcheng" style="width: 90px;" readonly="readonly" onclick="openProjListChoose()" required="true"/>
				<input type="hidden" id="projId"/>
				<!--供应商：<select class="easyui-combobox"  id="supplierId" name="supplier.id" style="width: 200px;" required=true data-options="required:true,panelHeight:'auto',valueField:'id',textField:'name',url:'/admin/supplier/comboList'"></select>-->
				&nbsp;&nbsp;&nbsp;&nbsp;发料单位：<input type="text" id="deptName" name="bumenmingcheng" size="10"
													readonly="readonly" onclick="openDeptListChoose()"
													 required="true"/>
				<input type="hidden" id="deptId"/>
				&nbsp;&nbsp;&nbsp;&nbsp;入库库房：<input type="text" id="storeName" name="rukukufang" size="10" readonly="readonly" onclick="openStoreListChoose()" required="true"/>
				<input type="hidden" id="storeId"/>
				<!-- -->
				&nbsp;&nbsp;&nbsp;日期：&nbsp;
				<input id="s_btime" name="s_btime" class="easyui-datebox" editable=false  style="width:100px">
				&nbsp;&nbsp;-&nbsp;&nbsp;
				<input id="s_etime" name="s_etime" class="easyui-datebox" editable=false  style="width:100px">
				&nbsp;&nbsp;<a href="javascript:searchYanshoudan()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
				&nbsp;&nbsp;<a href="javascript:deleteYanshoudan()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
				&nbsp;&nbsp;<a href="javascript:printYanshouDan()" class="easyui-linkbutton" iconCls="icon-print"
							   plain="true">打印</a>
			</fieldset>
		</div>
	</div>
</div>
<div region="center" style="margin-top: 5px;">
	<table id="dg2"  class="easyui-datagrid" fit=true pageList=[10,20,30,40,50,1000000]
		   fitColumns="true"  rownumbers="true"  pagination="true"  toolbar="#tbzi">
	<!--&gt;-->
		<thead>
		<tr>
			<!--展示验收单详细-->
			<!--<th field="ukyo" align="center" width="30" checkbox="true"></th>-->
			<th field="id" width="60" align="center" sortable="true" hidden="hidden">编号</th>
			<th field="duiyingdaohuodanhao" width="80" align="center" sortable="true">到货单号</th>
			<th field="wuliaobianma" width="75" align="center" sortable="true">物料编码</th>
			<th field="mingchengguige" width="100" align="center" sortable="true">名称规格</th>
			<th field="yingshoushuliang" width="50" align="center" sortable="true">应收数量</th>
			<th field="shishoushuliang" width="50" align="center" sortable="true">实收数量</th>
			<th field="danwei" width="40" align="center" sortable="true">单位</th>
			<th field="danjia" width="60" align="center" sortable="true">单价</th>
			<th field="zongjia" width="60" align="center" sortable="true">总价</th>
			<th field="beizhu" width="50" align="center" sortable="true">备注</th>
			<th field="createtime" width="70" align="center" sortable="true">创建时间</th>
		</tr>
		</thead>
	</table>
	<div id="tbzi">
		<div style="padding-bottom: 5px">
			<fieldset style="border-color: #E7F0FF">
				<legend>明细导出</legend>
				<a href="javascript:void(0)" id="export_excel" iconCls="icon-save" class="easyui-linkbutton"
				   plain="true">保存数据</a>
				- 点击'保存数据'导出下方明细
			</fieldset>
		</div>
	</div>
</div>

<!--查询项目列表-->
<div id="projList" class="easyui-dialog" style="width:800px;height:460px;"
	 closed="true" data-options="onClose:function(){$('#s_codeOrProjName').val('');}" >
	<div class="easyui-layout" style="width:100%;height:100%;">

		<div region="north" style="height: 50px;" >
			<div style="padding-top: 8px;padding-left: 40px;">
				&nbsp;项目名称或者项目编号：&nbsp;<input type="text" id="projSearch" size="30" onkeydown="if(event.keyCode==13) searchGoods()"/>
				<a href="javascript:searchProj()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
			</div>
		</div>
		<div region="west" style="width: 200px" title="项目分类" split="true" data-options="collapsible:false">
			<div style="overflow-x: auto; overflow-y: auto; height: 90%; width:98%;">
				<ul id="projTree" class="easyui-tree" style="padding: 10px"></ul>
			</div>
			<div style="position:absolute;bottom: 10px;left: 15px">
				<a href="javascript:saveProjChoose()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">选择</a>
				<!--<a id="del" href="javascript:deleteGoodsType()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',disabled:true">删除</a>-->
			</div>
		</div>
		<div region="center">
			<table id="projNameList" title="项目列表" class="easyui-datagrid"
				   fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
				   url="/admin/dproject/getSelective" fit="true" toolbar="#tb4">
				<thead>
				<tr>
					<th field="id" width="30" hidden=true align="center">编号</th>
					<th field="xiangmumingcheng" width="150" align="center">项目名称</th>
					<th field="createtime" width="90" align="left">创建时间</th>

				</tr>
				</thead>
			</table>
			<div id="tb4">
				<div>
					<a href="javascript:saveProjChoose()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">选择</a>
				</div>
			</div>
		</div>
	</div>
</div>

<!--查询仓库列表-->
<div id="storeList" class="easyui-dialog" style="width:800px;height:460px;"
	 closed="true" data-options="onClose:function(){$('#s_codeOrStoreName').val('');}" >
	<div class="easyui-layout" style="width:100%;height:100%;">

		<div region="north" style="height: 50px;" >
			<div style="padding-top: 8px;padding-left: 40px;">
				&nbsp;仓库名称或者仓库编号：&nbsp;<input type="text" id="storeSearch" size="30" onkeydown="if(event.keyCode==13) searchGoods()"/>
				<a href="javascript:searchProj()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
			</div>
		</div>
		<div region="west" style="width: 200px" title="仓库分类" split="true" data-options="collapsible:false">
			<div style="overflow-x: auto; overflow-y: auto; height: 90%; width:98%;">
				<ul id="storeTree" class="easyui-tree" style="padding: 10px"></ul>
			</div>
			<div style="position:absolute;bottom: 10px;left: 15px">
				<a href="javascript:saveStoreChoose()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">选择</a>
				<!--<a id="del" href="javascript:deleteGoodsType()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',disabled:true">删除</a>-->
			</div>
		</div>
		<div region="center">
			<table id="storeNameList" title="仓库列表" class="easyui-datagrid"
				   fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
				   url="/admin/dkufang/getSelective" fit="true" toolbar="#tb5">
				<thead>
				<tr>
					<th field="id" width="30" hidden=true align="center">编号</th>
					<th field="kufangmingcheng" width="150" align="center">仓库名称</th>
					<th field="createtime" width="90" align="left">创建时间</th>

				</tr>
				</thead>
			</table>
			<div id="tb5">
				<div>
					<a href="javascript:saveStoreChoose()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">选择</a>
				</div>
			</div>
		</div>
	</div>
</div>

<!--查询部门列表-->
<div id="deptList" class="easyui-dialog" style="width:800px;height:460px;"
	 closed="true" data-options="onClose:function(){$('#s_codeOrDeptName').val('');}">
	<div class="easyui-layout" style="width:100%;height:100%;">

		<div region="north" style="height: 50px;">
			<div style="padding-top: 8px;padding-left: 40px;">
				&nbsp;项目名称或者项目编号：&nbsp;<input type="text" id="deptSearch" size="30"
											  onkeydown="if(event.keyCode==13) searchGoods()"/>
				<a href="javascript:searchDept()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
			</div>
		</div>
		<div region="west" style="width: 200px" title="发料单位分类" split="true" data-options="collapsible:false">
			<div style="overflow-x: auto; overflow-y: auto; height: 90%; width:98%;">
				<ul id="deptTree" class="easyui-tree" style="padding: 10px"></ul>
			</div>
			<div style="position:absolute;bottom: 10px;left: 15px">
				<a href="javascript:saveDeptChoose(1)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">选择</a>
				<!--<a id="del" href="javascript:deleteGoodsType()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',disabled:true">删除</a>-->
			</div>
		</div>
		<div region="center">
			<table id="deptNameList" title="发料单位列表" class="easyui-datagrid"
				   fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
				   url="/admin/dbumen/getSelective" fit="true" toolbar="#tb-bm">
				<thead>
				<tr>
					<th field="id" width="30" hidden=true align="center">编号</th>
					<th field="bumenmingcheng" width="150" align="center">单位名称</th>
					<th field="createtime" width="90" align="left">创建时间</th>
				</tr>
				</thead>
			</table>
			<div id="tb-bm">
				<div>
					<a href="javascript:saveDeptChoose(2)" class="easyui-linkbutton" iconCls="icon-ok"
					   plain="true">选择</a>
				</div>
			</div>
		</div>
	</div>
</div>

<!--大屏幕上右键datagrid dlg-->
<div id="grid-data" class="easyui-menu" style="width: 80px; display: none;">
	<!--<div id="grid-data-edit" href="javascript:openDetailsModifyDialog()" data-options="iconCls:'icon-edit'">修改</div>-->
	<!--<div id="grid-data-delete" href="javascript:deleteDetails()" data-options="iconCls:'icon-remove'" plain="true">删除-->
	<!--</div>-->
</div>
<!--二级菜单右键弹出-->
<div id="tree-2" class="easyui-menu" style="width: 80px; display: none;">
	<!--<div id="tree-2-delete" href="javascript:deleteType()" data-options="iconCls:'icon-remove'">删除二级菜单</div>-->
</div>
<!--一级菜单右键弹出-->
<div id="tree-1" class="easyui-menu" style="width: 80px; display: none;">
	<!--<div id="tree-1-add-2" href="javascript:openTypeAddDialog()" data-options="iconCls:'icon-add'">添加二级菜单</div>-->
	<!--<div id="tree-1-delete" href="javascript:deleteType()" data-options="iconCls:'icon-remove'">删除一级菜单</div>-->
</div>
<!--树形菜单右键弹出-->
<div id="tree-0" class="easyui-menu" style="width: 80px; display: none;">
	<!--<div id="tree-0-add-1" href="javascript:openTypeAddDialog(0)" data-options="iconCls:'icon-add'">添加一级菜单</div>-->
	<!--<div id="tree-0-refresh" href="javascript:reloadTree()" data-options="iconCls:'icon-reload'">重新加载类别</div>-->
</div>



</body>

<script>
    function printYanshouDan() {
        var selectedRows = $("#dg").datagrid("getSelections");
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择要打印的验收单！");
            return;
        }
        // var selectedRows=$("#dg2").datagrid("getSelections");
        // if(selectedRows.length==0){
        //     $.messager.alert("系统提示","该单据无详细数据！");
        //     return;
        // }
        var headAndFootPrintArgs = new Array();
        var headTitle = [];
        var footTitle = [];
        headAndFootPrintArgs.push(headTitle);
        headAndFootPrintArgs.push(footTitle);
        createFormPage("物 料 验 收 单", $("#dg2"), $("#dg"), "验收打印", headAndFootPrintArgs);
    }
    // printName 打印任务名
    // printDatagrid 要打印的datagrid
    // strPrintName 打印任务名
    // printDatagrid 要打印的datagrid
    function createFormPage(strPrintName, printDatagrid, printDatagridZong, printEnum, headAndFootPrintArgs) {
        //单据表头
        var tableString = '<b>山东海盛海洋工程集团有限公司</b><br>';
        tableString += '<b>(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
            '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)</b><br>';
        tableString += '<h1 style="text-align: center;letter-spacing:7.5px;">' + strPrintName + '</h1><br>';
        //单据表头下的其他信息,不在table格子中的,格子之上
        if (printEnum == '验收打印') {
            console.log("验收打印");
            if (headAndFootPrintArgs[0] != null) {
                var x;
                //参数拼接
                var count1 = 0;
                for (x in headAndFootPrintArgs[0]) {//改为变参传入,可以通过printEnum后加一个,printArgs来结构化的传入要打印的数据对象
                    tableString += '<span class="col-md-12 args">' + '<b>' + headAndFootPrintArgs[0][x] + '</b>' + "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" + '</span>';
                    count1++;
                    if (count1 > 4) {
                        tableString += "<br><br><br>"
                    }
                }
            } else {
                console.log("null of printArgs.");
            }
        }
        tableString += '<br>';
        // start zong table
        tableString = tableString + '<div class="col-md-12 table-responsive"><table cellspacing="0" class="pb table text-nowrap">';
        // var frozenColumnsZong = printDatagridZong.datagrid("options").frozenColumns;  // 得到frozenColumns对象
        // var frozenColumnsZong = printDatagridZong.frozenColumns;  // 得到frozenColumns对象
        var frozenColumnsZong = printDatagridZong.datagrid("options").frozenColumns;  // 得到frozenColumns对象
        var columnsZong = printDatagridZong.datagrid("options").columns;    // 得到columns对象
        // var columnsZong = printDatagridZong.columns;    // 得到columns对象
        var nameListZong = '';
        // 载入title
        if (typeof columnsZong != 'undefined' && columnsZong != '' && columnsZong != 'ukyo') {
            tableString += '\n<thead>'
            console.log(columnsZong);
            $(columnsZong).each(function (index) {
                tableString += '\n<tr>';
                if (typeof frozenColumnsZong != 'undefined' && typeof frozenColumnsZong[index] != 'undefined') {
                    for (var i = 0; i < frozenColumnsZong[index].length; ++i) {
                        if (!frozenColumnsZong[index][i].hidden && frozenColumnsZong[index][i] != 'ukyo') {
                            console.log("frozenColumnsZong[index][i]" + frozenColumnsZong[index][i])
                            tableString += '\n<th width="' + frozenColumnsZong[index][i].width + '"';
                            if (typeof frozenColumnsZong[index][i].rowspan != 'undefined' && frozenColumnsZong[index][i].rowspan > 1) {
                                tableString += ' rowspan="' + frozenColumnsZong[index][i].rowspan + '"';
                            }
                            if (typeof frozenColumnsZong[index][i].colspan != 'undefined' && frozenColumnsZong[index][i].colspan > 1) {
                                tableString += ' colspan="' + frozenColumnsZong[index][i].colspan + '"';
                            }
                            if (typeof frozenColumnsZong[index][i].field != 'undefined' && frozenColumnsZong[index][i].field != '' && frozenColumnsZong[index][i].field != 'ukyo') {
                                nameListZong += ',{"f":"' + frozenColumnsZong[index][i].field + '", "a":"' + frozenColumnsZong[index][i].align + '"}';
                            }
                            tableString += '>' + frozenColumnsZong[0][i].title + '</th>';
                        }
                    }
                }
                for (var i = 0; i < columnsZong[index].length; ++i) {
                    if (!columnsZong[index][i].hidden) {
                        tableString += '\n<th width="' + columnsZong[index][i].width + '"';
                        if (typeof columnsZong[index][i].rowspan != 'undefined' && columnsZong[index][i].rowspan > 1) {
                            tableString += ' rowspan="' + columnsZong[index][i].rowspan + '"';
                        }
                        if (typeof columnsZong[index][i].colspan != 'undefined' && columnsZong[index][i].colspan > 1) {
                            tableString += ' colspan="' + columnsZong[index][i].colspan + '"';
                        }
                        if (typeof columnsZong[index][i].field != 'undefined' && columnsZong[index][i].field != '' && columnsZong[index][i].field != 'ukyo') {
                            nameListZong += ',{"f":"' + columnsZong[index][i].field + '", "a":"' + columnsZong[index][i].align + '"}';
                        }
                        tableString += '>' + columnsZong[index][i].title + '</th>';
                    }
                }
                tableString += '\n</tr>';
            });
        }
        tableString += '\n</thead>'
        // 载入内容
        var rowsZong = printDatagridZong.datagrid("getSelections"); // 这段代码是获取当前页的选中行
        // var rowsZong = printDatagridZong[0]; // 这段代码是获取当前页的所有行
        var nl = eval('([' + nameListZong.substring(1) + '])');
        tableString += '\n<tbody>'
        for (var i = 0; i < rowsZong.length; ++i) {
            tableString += '\n<tr>';
            $(nl).each(function (j) {
                var e = nl[j].f.lastIndexOf('_0');

                tableString += '\n<td';
                if (nl[j].a != 'undefined' && nl[j].a != '' && nl[j].a != 'ukyo') {
                    tableString += ' style="text-align:' + nl[j].a + ';"';
                }
                tableString += '>';
                if (e + 2 == nl[j].f.length) {
                    if (typeof rowsZong[i][nl[j].f] != 'undefined' && typeof rowsZong[i][nl[j].f] != 'null') {
                        tableString += rowsZong[i][nl[j].f.substring(0, e)];
                    } else {
                    }
                }
                else{
                    if (typeof rowsZong[i][nl[j].f] != 'undefined' && typeof rowsZong[i][nl[j].f] != 'null') {
                        tableString += rowsZong[i][nl[j].f];
                    } else {
                    }
				}
                tableString += '</td>';
            });
            tableString += '\n</tr>';
        }
        tableString += '\n</tbody>'
        tableString += '\n</table>';
        tableString += '\n</div>';
        //end zong table
        tableString += '\n<br />';
        tableString += '\n<br />';

        //start sub datagrid
        tableString = tableString + '<div class="col-md-12 table-responsive"><table cellspacing="0" class="pb table text-nowrap">';
        var frozenColumns = printDatagrid.datagrid("options").frozenColumns;  // 得到frozenColumns对象
        var columns = printDatagrid.datagrid("options").columns;    // 得到columns对象
        var nameList = '';
        // 载入title
        if (typeof columns != 'undefined' && columns != '') {
            tableString += '\n<thead>'
            $(columns).each(function (index) {
                tableString += '\n<tr>';
                if (typeof frozenColumns != 'undefined' && typeof frozenColumns[index] != 'undefined') {
                    for (var i = 0; i < frozenColumns[index].length; ++i) {
                        if (!frozenColumns[index][i].hidden) {
                            tableString += '\n<th width="' + frozenColumns[index][i].width + '"';
                            if (typeof frozenColumns[index][i].rowspan != 'undefined' && frozenColumns[index][i].rowspan > 1) {
                                tableString += ' rowspan="' + frozenColumns[index][i].rowspan + '"';
                            }
                            if (typeof frozenColumns[index][i].colspan != 'undefined' && frozenColumns[index][i].colspan > 1) {
                                tableString += ' colspan="' + frozenColumns[index][i].colspan + '"';
                            }
                            if (typeof frozenColumns[index][i].field != 'undefined' && frozenColumns[index][i].field != '' && frozenColumns[index][i].field != 'ukyo') {
                                nameList += ',{"f":"' + frozenColumns[index][i].field + '", "a":"' + frozenColumns[index][i].align + '"}';
                            }
                            tableString += '>' + frozenColumns[0][i].title + '</th>';
                        }
                    }
                }
                for (var i = 0; i < columns[index].length; ++i) {
                    if (!columns[index][i].hidden) {
                        tableString += '\n<th width="' + columns[index][i].width + '"';
                        if (typeof columns[index][i].rowspan != 'undefined' && columns[index][i].rowspan > 1) {
                            tableString += ' rowspan="' + columns[index][i].rowspan + '"';
                        }
                        if (typeof columns[index][i].colspan != 'undefined' && columns[index][i].colspan > 1) {
                            tableString += ' colspan="' + columns[index][i].colspan + '"';
                        }
                        if (typeof columns[index][i].field != 'undefined' && columns[index][i].field != '' && columns[index][i].field != 'ukyo') {
                            nameList += ',{"f":"' + columns[index][i].field + '", "a":"' + columns[index][i].align + '"}';
                        }
                        tableString += '>' + columns[index][i].title + '</th>';
                    }
                }
                tableString += '\n</tr>';
            });
        }
        tableString += '\n</thead>'
        // 载入内容
        var rows = printDatagrid.datagrid("getRows"); // 这段代码是获取当前页的所有行
        var nl = eval('([' + nameList.substring(1) + '])');
        tableString += '\n<tbody>'
        for (var i = 0; i < rows.length; ++i) {
            tableString += '\n<tr>';
            $(nl).each(function (j) {
                var e = nl[j].f.lastIndexOf('_0');

                tableString += '\n<td';
                if (nl[j].a != 'undefined' && nl[j].a != '') {
                    tableString += ' style="text-align:' + nl[j].a + ';"';
                }
                tableString += '>';
                if (e + 2 == nl[j].f.length) {
                    if (typeof rows[i][nl[j].f] != 'undefined') {
                        tableString += rows[i][nl[j].f.substring(0, e)];
                    } else {
                    }
                }
                else {
                    if (typeof rows[i][nl[j].f] != 'undefined') {
                        tableString += rows[i][nl[j].f];
                    } else {
                    }
                }
                tableString += '</td>';
            });
            tableString += '\n</tr>';
        }
        tableString += '\n</tbody>';
        tableString += '\n</table>';
        tableString += '\n</div>';
        //end of sub table

        if (headAndFootPrintArgs[1] != null) {
            var x;
            //参数拼接
            var count2 = 0;
            for (x in headAndFootPrintArgs[1]) {//改为变参传入,可以通过printEnum后加一个,printArgs来结构化的传入要打印的数据对象
                tableString += '<span class="col-md-12 args">' + '<b>' + headAndFootPrintArgs[1][x][0] + '</b>' + headAndFootPrintArgs[1][x][1] + "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" + '</span>';
                count2++;
                if (count2 > 3) {
                    tableString += "<br><br><br>"
                }
            }
        } else {
            console.log("null of printArgs.");
        }

        localStorage.setItem("tableString", tableString);
        window.location.href = "print.html";
        // window.open("print.html", tableString,"location=no, status=no;help:no;toolbar=no, menubar=no, scrollbars=no, resizeable=no,dialogWidth:800px;top:0;left:0;dialogHeight:600px;scroll:auto;");
    }

    // var printConfig = {
    //     companyName: 'HS',
    //     printTime: new Date()
    // }
</script>
<script>
    // 导出excel按钮
    $("#export_excel").click(exportExcel);

    // 导出excel
    function exportExcel() {
        //获得选中记录 多选
        var row = $('#dg2').datagrid('getRows');
        // var row = $('#dg').datagrid('getSelections');
        // 去除不需要导出的实体字段
        var deleteKey = ['updatetime',
            'zongzhangid', 'sort', 'order'
        ];
        for (var i in row) {
            for (var j in deleteKey) {
                delete row[i][deleteKey[j]];
            }
        }
        if (row) {
            $.messager.confirm('确认按钮', '你确定要导出本页验收明细数据?', function (r) {
                if (r) {
                    downloadExl(row);
                }
            })
        }
    }

    function downloadExl(data, type) {
        var keys = Object.keys(data[0]);
        var firstRow = {};
        keys.forEach(function (item) {
            console.log("item:" + item);
            firstRow[item] = item;
        });
        data.unshift(firstRow);

        var content = {};

        //把json格式的数据转换为excel的行列形式
        var sheetsData = data.map(function (item, rowIndex) {
            return keys.map(function (key, columnIndex) {
                return Object.assign({}, {
                    value: item[key],
                    position: (columnIndex > 25 ? getCharCol(columnIndex) : String.fromCharCode(65 + columnIndex)) + (rowIndex + 1),
                });
            });
        }).reduce(function (prev, next) {
            return prev.concat(next);
        });

        sheetsData.forEach(function (item, index) {
            // content[item.position] = {v: item.value};
            if (item.value == 'id') {
                content[item.position] = {v: '序列号'};
            } else if (item.value == 'duiyingdaohuodanhao') {
                content[item.position] = {v: '到货单号'};
            }  else if (item.value == 'wuliaobianma') {
                content[item.position] = {v: '物料编码'};
            } else if (item.value == 'mingchengguige') {
                content[item.position] = {v: '名称规格'};
            } else if (item.value == 'yingshoushuliang') {
                content[item.position] = {v: '应收数量'};
            } else if (item.value == 'shishoushuliang') {
                content[item.position] = {v: '实收数量'};
            } else if (item.value == 'danwei') {
                content[item.position] = {v: '单位'};
            } else if (item.value == 'danjia') {
                content[item.position] = {v: '单价'};
            } else if (item.value == 'zongjia') {
                content[item.position] = {v: '总价'};
            } else if (item.value == 'beizhu') {
                content[item.position] = {v: '备注'};
            }  else if (item.value == 'createtime') {
                content[item.position] = {v: '创建时间'};
            } else {
                if (item.value == null || item.value == undefined || item.value == 'null') {
                    content[item.position] = {v: ''};  //remember
                } else {
                    content[item.position] = {v: item.value};  //remember
                }
            }
        });

        //设置区域,比如表格从A1到D10,SheetNames:标题
        var coordinate = Object.keys(content);
        var workBook = {
            SheetNames: ["1"],
            Sheets: {
                "1": Object.assign({}, content, {"!ref": coordinate[0] + ":" + coordinate[coordinate.length - 1]}),
            }
        };

        //这里的数据是用来定义导出的格式类型
        var excelData = XLSX.write(workBook, {bookType: "xlsx", bookSST: false, type: "binary"});
        var blob = new Blob([string2ArrayBuffer(excelData)], {type: ""});

        // filename = "石油焦";
        $.messager.prompt("输入框", "请输入保存文件名.", function (filename) {
            if (filename) {
                var nowTime = new Date().toLocaleDateString();
                saveAs(blob, filename + "-验收明细" + nowTime + ".xlsx"); //文件名
            }
        });
    }

    //字符串转字符流
    function string2ArrayBuffer(s) {
        var buf = new ArrayBuffer(s.length);
        var view = new Uint8Array(buf);
        for (var i = 0; i != s.length; ++i) {
            view[i] = s.charCodeAt(i) & 0xFF;
        }
        return buf;
    }

    //将指定的自然数转换为26进制表示. 映射关系: [0-25] -> [A-Z]
    function getCharCol(n) {
        var temCol = "",
            s = "",
            m = 0;
        while (n > 0) {
            m = n % 26 + 1;
            s = String.fromCharCode(m + 64) + s;
            n = (n - m) / 26;
        }
        return s;
    }

</script>
</html>